package com.learn.use.myreconsituteproject.login.model;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.learn.use.myreconsituteproject.http.Urls;
import com.learn.use.myreconsituteproject.login.bean.LoginBean;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

/**
 * Created by 聪明一只哈 on 2018/9/11.
 * Time: 2018/9/11  16:55
 */
public class LoginMode implements BaseLoginModel {


    /**
     * 登录访问
     * @param count_num
     * @param count_pwd
     * @param loginOnLoadListener
     */
    @Override
    public void loadGrild(String count_num, String count_pwd, final LoginOnLoadListener loginOnLoadListener) {
        OkGo.<String>post(Urls.LOGIN)
                .tag(this)
                .params("username", count_num)
                .params("password", count_pwd)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        String loginData = response.body();
                        if (loginData != null) {

                            Log.i("登录数据", "onSuccess: " + loginData);
                            LoginBean loginBean = JSON.parseObject(loginData, LoginBean.class);
                            loginOnLoadListener.onComplete(loginBean);
                        }
                    }
                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        Log.i("登录数据", "onError: " + response.message());
                        loginOnLoadListener.onFiled(response.message());
                    }
                });

    }
}
